
const { ccclass, property } = cc._decorator;
const alertAnimSpeed = 0.45;


@ccclass
export default class PanelBase extends cc.Component {


    protected onEnable(): void {
        this.windowShow();
    }

    private windowShow() {
        let mask = this.node.getChildByName("mask");
        if (mask) mask.active = true;
        let content = this.node.getChildByName("content");
        content = content ? content : this.node;
        if (content) {
            cc.Tween.stopAllByTarget(content);
            content.setScale(0);
            cc.tween(content)
                .parallel(
                    cc.tween().to(alertAnimSpeed, { opacity: 255 }),
                    cc.tween().to(alertAnimSpeed, { scale: 1 }, { easing: 'backOut' })
                )
                .start()
        } else {
            console.error("windowShow cannot find content");
        }
    }

    private windowHide() {
        let mask = this.node.getChildByName("mask");
        if (mask) mask.active = false;
        let content = this.node.getChildByName("content");
        content = content ? content : this.node;
        if (content) {
            cc.Tween.stopAllByTarget(content);
            cc.tween(content)
                .parallel(
                    cc.tween().to(alertAnimSpeed, { opacity: 150, }),
                    cc.tween().to(alertAnimSpeed, { scale: 0 }, { easing: 'backIn' })
                )
                .call(() => { this.node.active = false; })
                .start()
        } else {
            console.error("windowHide cannot find content");
        }
    }

    onClose() {
        this.windowHide();
    }
}
